﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace QL_NOI_TRU
{
    public partial class frmNhapDSPhongBenh : DevExpress.XtraEditors.XtraForm
    {
        public frmNhapDSPhongBenh()
        {
            InitializeComponent();
        }

        private void frmNhapDSPhongBenh_Load(object sender, EventArgs e)
        {
            // do du lieu vao grid
            var kn = new Ketnoi(frmDangnhap.stringConn);
            gridControl1.DataSource = kn.ExcuteQuery("select MAPHONG as 'Mã phòng',TEN_KHOA as 'Tên khoa', PHONG_BENH.GIATIEN as 'Giá tiền' from KHOA,PHONG_BENH where KHOA.MA_KHOA = PHONG_BENH.MA_KHOA ");

            //do du lieu vao cbbKhoa
            var a = "select * from KHOA";
            SqlConnection conn = new SqlConnection(frmDangnhap.stringConn);
            SqlCommand cm = conn.CreateCommand();
            cm.CommandText = a;
            conn.Open();
            SqlDataReader dr = cm.ExecuteReader();
            while (dr.Read())
            {
                cbbKhoa.Properties.Items.Add(String.Format("{0} | {1}", dr["MA_KHOA"], dr["TEN_KHOA"]));
            }
            dr.Close();
        }

        private void btLuu_Click(object sender, EventArgs e)
        {
            string strr = "EXEC Insert_PHONG_BENH @MA_KHOA='" + cbbKhoa.Text.Substring(0, 2).Trim() + "',@MAPHONG = '" + txtMaPhong.Text.ToString().Trim() + "',@GIATIEN='" + txtGia.Text.ToString().Trim() + "'";
            var kn = new Ketnoi(frmDangnhap.stringConn);
            kn.ExcuteQuery(strr);
            btRefresh_Click(null, null);

        }

        private void btXoaGiuong_Click(object sender, EventArgs e)
        {
            this.Hide();
            var f = new frmNhapDanhSachKhoa();
            f.Show();
        }

        private void btRefresh_Click(object sender, EventArgs e)
        {
            cbbKhoa.SelectedIndex = -1;
            txtMaPhong.Text = "";
            txtGia.Text = "";
            frmNhapDSPhongBenh_Load(null, null);
        }

        private void cbbKhoa_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                txtMaPhong.Focus();
        }
    }
}